home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual dBase v5.5 / MUSIC1.PAK / MUSIC.PRG < prev    next >
Encoding:
Text File  |  1995-07-18  |  15.4 KB  |  479 lines

  1. *******************************************************************************
  2. *  PROGRAM:      Music.prg
  3. *
  4. *  WRITTEN BY:   Borland Samples Group
  5. *
  6. *  DATE:         4/94
  7. *
  8. *  UPDATED:      5/95
  9. *
  10. *  REVISION:     $Revision:   1.37  $
  11. *
  12. *  VERSION:      Visual dBASE
  13. *
  14. *  DESCRIPTION:  This program is an illustration of how a record store,
  15. *                Musical Methods, displays its music collection information.
  16. *                This program will allow you to view the available music
  17. *                in various orders, look at separate tables of music categories,
  18. *                sales rankings, and media types available.  You can search for
  19. *                information, and look at the available data in various
  20. *                formats.  This file is both the starting program and the
  21. *                procedure file for all forms called in the application.
  22. *
  23. *  PARAMETERS:   None
  24. *
  25. *  CALLS:        Musiview.wfm    (main music form)
  26. *
  27. *  USAGE:        DO Music
  28. *
  29. *******************************************************************************
  30. #include "Music.h"
  31. #include <Messdlg.h>
  32. #include <Enum.h>
  33.  
  34. *** Basic Environment
  35. create session
  36. set talk off
  37.  
  38. *** Procedure Files
  39. set procedure to program(1) additive    && Make procedures in this file available
  40.  
  41. *** Public Variables
  42. * trackWindows -- window tracking and environment storage variable
  43. public trackWindows
  44.  
  45. trackWindows = new TrackWindowsClass()  && Set up window tracking, and
  46.                                         && application environment
  47. *** Show Music
  48. do Musiview.wfm
  49.  
  50.  
  51. ******************************* Classes ***************************************
  52.  
  53. *******************************************************************************
  54. *******************************************************************************
  55. CLASS TrackWindowsClass
  56.  
  57. * This class keeps track of open and closed view windows.  It stores
  58. * references to those windows in an array, windowAr, and deletes those
  59. * references when the window is closed.  Each window gets assigned
  60. * a windowNum property -- its index in the array.
  61. *******************************************************************************
  62.    *** Constructor
  63.  
  64.    * Save Environment
  65.    shell(.F., .T.)                         && Close Visual dBASE desktop windows
  66.    this.saveFrameText = _app.frameWin.text && Save previous frame title
  67.    this.saveHelp = setto("help")           && Save help file
  68.  
  69.    * Set Environment
  70.    _app.framewin.text = "Musical Methods"  && Application title
  71.    set help to music.hlp                   && Help file for the program
  72.  
  73.    * Window tracking properties
  74.    this.windowAr = new array(0)            && Array for storing windows
  75.    this.windowCnt = 0                      && Count of open windows
  76.  
  77.  
  78.    ****************************************************************************
  79.    procedure AddWindow(f)
  80.  
  81.    * Routine called whenever a new window is opened
  82.    ***************************************************************************
  83.  
  84.    this.windowAr.Add(f)
  85.    f.windowNum = this.windowAr.size
  86.    this.windowCnt = this.windowCnt + 1          && Increase count of open wind
  87.  
  88.  
  89.  
  90.    ***************************************************************************
  91.    procedure DeleteWindow(f)
  92.  
  93.    * Routine called whenever a window is closed
  94.    ***************************************************************************
  95.  
  96.    this.windowAr[f.windowNum] = .F.
  97.    this.windowCnt = this.windowCnt - 1          && Decrease count of open wind
  98.    if this.windowCnt = 0                        && If no more windows,
  99.       this.RestoreEnvironment()                 && restore environment
  100.    endif
  101.  
  102.  
  103.    ***************************************************************************
  104.    procedure DeleteAllWindows
  105.  
  106.    * Routine to close all open windows
  107.    ***************************************************************************
  108.    private i, windowArSize
  109.  
  110.    windowArSize = this.windowAr.size
  111.    for i = 1 to windowArSize
  112.       if type("this.windowAr[i]") <> "L"
  113.          this.windowAr[i].OnClose = .F.
  114.          this.windowAr[i].Close()
  115.       endif
  116.    next i
  117.  
  118.  
  119.    ***************************************************************************
  120.    procedure RestoreEnvironment
  121.  
  122.    * Restore previous environment
  123.    ***************************************************************************
  124.    private saveFrameText, saveHelp
  125.  
  126.    saveFrameText = this.saveFrameText           && Assign properties to vars
  127.    saveHelp = this.saveHelp
  128.  
  129.    _app.framewin.text = saveFrameText           && Restore frame text
  130.    set help to &saveHelp                        && Restore help file
  131.  
  132.    shell(.T.)                                   && Restore Visual dBASE shell
  133.  
  134.  
  135. ENDCLASS
  136.  
  137.  
  138. *************************** Views Procedures **********************************
  139.  
  140. ******************************************************************************
  141. procedure EnableViews(f)
  142.  
  143. * This is called when a the full Music application is run (this file)
  144. * to enable viewing of all types of forms.  By default these menus
  145. * are disabled, so you cannot call other forms when you run just one
  146. * of the view forms on its own -- i.e. do Musiview.wfm
  147. ******************************************************************************
  148.  
  149. f.root.view.music.enabled = .T.
  150. f.root.view.categories.enabled = .T.
  151. f.root.view.rankings.enabled = .T.
  152. f.root.view.media_types.enabled = .T.
  153.  
  154.  
  155. *******************************************************************************
  156. procedure DefineCorrespondingItems(form)
  157.  
  158. * Define items corresponding to current selection in
  159. * Categories/Rankings/Media Types forms.  Items are initially not visible
  160. *******************************************************************************
  161.  
  162. DEFINE RECTANGLE DIVIDERRECT OF FORM;
  163.     PROPERTY;
  164.       ColorNormal form.colorNormal,;
  165.       Text "",;
  166.       Height         form.height,;
  167.       Width          0.34,;
  168.       Top          0.00,;
  169.       Left         form.width,;
  170.       Border .T.,;
  171.       Visible .F.
  172.  
  173. DEFINE BROWSE ITEMSBROWSE OF FORM;
  174.     PROPERTY;
  175.       ShowRecNo .F.,;
  176.       Modify .F.,;
  177.       Toggle .F.,;
  178.       Width         MAX_FORM_WIDTH - form.dividerRect.left,;
  179.       Top           1.01,;
  180.       Left          form.dividerRect.left + .5,;
  181.       Height        form.height - 3,;
  182.       Alias "Music",;
  183.       Fields "Music->Artist, Music->Title, Music->Rank",;
  184.       ColorNormal "r/w",;
  185.       FontSize          8.00,;
  186.       FontName "MS Sans Serif",;
  187.       FontBold .F.,;
  188.       Delete .F.,;
  189.       Visible .F.
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196. *******************************************************************************
  197. procedure CorrespondingItems
  198.  
  199. * Expand window to show items corresponding to current selection
  200. *******************************************************************************
  201. private key
  202.  
  203. if .not. form.MusicIsOpen              && Check if browse is already open
  204.    form.MusicIsOpen = .T.
  205. endif
  206.  
  207. * Make corresponding items controls visible
  208. form.dividerRect.visible = .T.
  209. form.itemsBrowse.visible = .T.
  210.  
  211. this.text     = "No &Items"
  212. this.helpId   = "No Items"
  213. this.OnClick  = NoCorrespItems
  214. this.StatusMessage = "Remove displayed browse of items.  Press F1 for Help."
  215. form.width    = MAX_FORM_WIDTH
  216. form.left     = 0.00
  217. go recno()
  218.  
  219.  
  220. *******************************************************************************
  221. procedure NoCorrespItems
  222.  
  223. * Shrink window to not show items corresponding to current selection
  224. *******************************************************************************
  225.  
  226. this.text          = "&Items..."
  227. this.helpId        = "Items"
  228. this.OnClick       = CorrespondingItems
  229. this.statusMessage = "Show available items that match the current selection.  Press F1 for Help."
  230. form.width         = form.dividerRect.left - 1
  231. form.left          = 27.03
  232.  
  233. * Make corresponding items controls invisible
  234. form.dividerRect.visible = .F.
  235. form.itemsBrowse.visible = .F.
  236.  
  237.  
  238.  
  239. *******************************************************************************
  240. procedure SizeForm(nType, width, newHeight)
  241.  
  242. * Resize form controls as the form gets resized.
  243. ******************************************************************************
  244.  
  245. height = max(MIN_FORM_HEIGHT, newHeight)
  246. if form.windowState <> WINDOWSTATE_MINIMIZED          && if not minimized
  247.    if .not. form.MusicIsOpen         && If only have a listbox
  248.       form.descriptList.height = height - 9
  249.    endif
  250.  
  251.    form.itemsButton.top          = PB_ROW(height)
  252.    form.closeFormButton.top      = PB_ROW(height)
  253.    form.logoImage.top            = height - 4.53
  254.    form.listRect.height          = height - 6
  255.    form.descriptList.height      = height - 8
  256.    if form.itemsButton.text = "No &Items"
  257.       form.dividerRect.height = height
  258.       form.itemsBrowse.height = height - 2
  259.       form.width = form.itemsBrowse.left + form.itemsBrowse.width + 1
  260.    else
  261.       form.width = form.descriptList.left + form.descriptList.width + 3
  262.    endif
  263. endif
  264.  
  265. ********************** Menu and Popup Procedures *****************************
  266.  
  267. *******************************************************************************
  268.  
  269. procedure CallShowRankView(form)
  270.  
  271. * Display form in Rank order
  272. *******************************************************************************
  273.  
  274. form.ShowRankView(form.root.view.organization.rank,;
  275.                   form.popupMenu.organization.rank)
  276.  
  277.  
  278. *******************************************************************************
  279.  
  280. procedure CallShowArtistsView(form)
  281.  
  282. * Display form in Artists Order
  283. *******************************************************************************
  284.  
  285. * WORKAROUND -- "This" as a parameter to another object will translate to
  286. *               that other object, not the current one
  287. form.ShowArtistsView(form.root.view.organization.artist,;
  288.                      form.popupMenu.organization.artist)
  289.  
  290.  
  291. *******************************************************************************
  292.  
  293. procedure CallShowTitlesView(form)
  294.  
  295. * Display form in Titles  Order
  296. *******************************************************************************
  297.  
  298. form.ShowTitlesView(form.root.view.organization.title,;
  299.                     form.popupMenu.organization.title)
  300.  
  301.  
  302. *******************************************************************************
  303.  
  304. procedure BrowseEdit(form)
  305.  
  306. * Display form in Browse format
  307. *******************************************************************************
  308.  
  309. form.BrowseView()  && In the current form's file
  310.  
  311.  
  312. *******************************************************************************
  313.  
  314. procedure FilterView(form)
  315.  
  316. * Set up filter form
  317. *******************************************************************************
  318. private filterForm, selected, tempFilt, curTable, saveCentury
  319.  
  320. curTable = alias()
  321. if .not. empty(form.filter)
  322.    if ConfirmationMessage(FormatStr(;
  323.                                     "Current filter is\n %1.\n" +;
  324.                                     "Do you want to turn it off?",;
  325.                                     form.filter),;
  326.                           "Confirmation") = YES
  327.       select music
  328.       set filter to
  329.       go top
  330.       select &curTable
  331.       set filter to
  332.       go top
  333.       form.filter = ""
  334.       SetTopBotRecs(form)
  335.    endif
  336. else
  337.    saveCentury = set("century")         && Allow specification of full year
  338.    set century on
  339.    set procedure to Filter.wfm additive
  340.    filterForm = new FilterForm()
  341.    filterForm.mdi = .F.
  342.    filterForm.viewForm = form
  343.    selected = filterForm.ReadModal()
  344.    set century &saveCentury
  345.    if type("selected") = "O" .and. selected.id <> 0
  346.                                                  && If Cancel wasn't pressed
  347.       SetTopBotRecs(form)
  348.    endif
  349.    filterForm.Release()
  350.    form.SetFocus()
  351.    if alias() = "MUSIC"     && If in Musiview form view, call its OnNavigate
  352.       form.OnNavigate()
  353.    endif
  354. endif
  355.  
  356.  
  357.  
  358. *******************************************************************************
  359.  
  360. procedure SearchItems(form)
  361.  
  362. * Search for an item.  Brings up a dialog for specifying an item to searh for.
  363. *******************************************************************************
  364. private searchForm, searchResult, saveFields, field2
  365.  
  366. if .not. empty(form.filter)          && If a filter has been set up
  367.    if ConfirmationMessage(FormatStr(;
  368.                                     "Current filter is\n %1.\n" +;
  369.                                     "Do you want to turn it off?",;
  370.                                     form.filter),;
  371.                           "Confirmation") = YES
  372.       set filter to                  && Clear filter
  373.       form.filter = ""
  374.    endif
  375. endif
  376. saveFields = setto("fields")
  377. if alias() <> "MUSIC"    && Make only the Descript field available.
  378.    field2 = field(2)
  379.    set fields to
  380.    set fields to &field2
  381. else
  382.    set fields to
  383. endif
  384.  
  385. set procedure to Search.wfm additive
  386. searchForm = new SearchForm()
  387. searchForm.mdi = .F.
  388. searchResult = searchForm.Readmodal()
  389. searchForm.Release()
  390. set fields to &saveFields
  391. if alias() = "MUSIC"     && If in Musiview form, call its OnNavigate
  392.    form.OnNavigate()
  393. endif
  394.  
  395.  
  396. *******************************************************************************
  397.  
  398. procedure SkipItems(form)
  399.  
  400. * Skip to a specified record.  Brings up a dialog for specifying how far
  401. * to skip.
  402. *******************************************************************************
  403. local skipForm
  404.  
  405. set procedure to Skip.wfm additive
  406. skipForm = new SkipForm()
  407. skipForm.mdi = .F.       && Do this here so can use Form Designer on form
  408. skipForm.ReadModal()
  409. skipForm.Release()
  410. if alias() = "MUSIC"     && If in Musiview form view, call its OnNavigate
  411.    form.OnNavigate()
  412. endif
  413.  
  414.  
  415.  
  416.  
  417.  
  418. *************************** Utility Procedures *******************************
  419.  
  420. ******************************************************************************
  421. procedure SetTopBotRecs(f)
  422.  
  423. * Stores the first and last records for the current display order.
  424. ******************************************************************************
  425.  
  426. go top
  427. f.firstRec = recno()
  428. go bottom
  429. f.lastRec = recno()
  430. go f.firstRec
  431.  
  432.  
  433.  
  434. ******************************************************************************
  435. function FormatStr(string)
  436.  
  437. * Could have 0 or more parameters.
  438. * This function will replace occurrences of "%<n>" with the corresponding
  439. * parameter string.  It will also replace all occurrences of "\n" with a
  440. * Carriage Return, and all occurrences of "\t" with a Tab.
  441. *
  442. * Example: x = FormatStr("Hello \n %1", "World") && prints Hello World on 2
  443. *                                                && lines
  444. ******************************************************************************
  445. #define ENTER  chr(13)
  446. #define TAB    chr(9)
  447. local i, strPos, strCnt, tmpStr
  448.  
  449. tmpStr = string
  450. for i = 2 to argc()    && while have something to search for
  451.    tmpStr = StrTran(tmpStr, "%" + ltrim(str(i - 1)), argv(i))
  452. next
  453. tmpStr = StrTran(tmpStr, "\n", ENTER)
  454. tmpStr = StrTran(tmpStr, "\t", TAB)
  455.  
  456. return tmpStr
  457.  
  458.  
  459. ******************************************************************************
  460. function StrTran(string,curStr,repStr)
  461.  
  462. * Replaces all occurrences of curStr in string with repStr
  463. ******************************************************************************
  464. local strPos, lenCurStr, tmpStr
  465.  
  466. tmpStr = string
  467. lenCurStr = len(curStr)
  468. strPos = at(curStr,tmpStr)
  469. do while strPos > 0
  470.    tmpStr = stuff(tmpStr, strPos, lenCurStr, repStr)
  471.    strPos = at(curStr,tmpStr)
  472. enddo
  473.  
  474. return tmpStr
  475.  
  476.  
  477.  
  478.  
  479.